﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Configuration;

public partial class admin_reminder : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DateTime dt = DateTime.UtcNow.Date;
        DateTime dateTime = DateTime.UtcNow.Date;
        // Response.Write(dateTime.ToString("yyyy/M/dd"));
        string s_date = dateTime.ToString("yyyy/M/dd");
        Label5.Text = s_date;
        Label5.Visible = false;
        GridView1.Visible = true;

        Label2.Text = Session["email"].ToString();

    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        if (e.CommandName == "download")
        {


            string fileName = string.Empty;

            int index = Convert.ToSByte(e.CommandArgument);

            GridViewRow row = GridView1.Rows[index];

            int docid = Convert.ToSByte(GridView1.DataKeys[index].Value);

            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);
            //SqlConnection con = new SqlConnection("Data Source=MRINAL-PC;Initial Catalog=onlinejobportal;User Id=sa;Password=mrinal");
            SqlCommand cmd = new SqlCommand("SELECT action_,c_id,added_by,c_name,Type_, DocName,DocData FROM task WHERE docid = " + docid, con);

            con.Open();

            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {

                fileName = dr["DocName"].ToString();

                byte[] documentBinary = (byte[])dr["DocData"];

                FileStream fStream = new FileStream(Server.MapPath("Docs") + @"\" + fileName, FileMode.Create);

                fStream.Write(documentBinary, 0, documentBinary.Length);

                fStream.Close();

                fStream.Dispose();

            }

            con.Close();

            Response.Redirect(@"Docs\" + fileName);

        }
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}